package mhys.Dao;

import mhys.Entity.Classes;
import mhys.Entity.Student;
import mhys.Util.DBUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ClassesDao extends BaseDao{
    public int addClass(Classes classes) {
        String sql = "insert into class values(null,?,?,?)";
        return insertUpdateDelete(sql,classes.getC_name(),classes.getMajor(),classes.getT_name());
    }

    public List<Classes> getClasses() {
        String sql = "select c_name from class";
        List<Classes> classes = new ArrayList<Classes>();
        try {
            res = select(sql);
            while (res.next()){
                Classes classes1 = new Classes();
                classes1.setC_name(res.getString("c_name"));
                classes.add(classes1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DBUtil.close(res,stmt,conn);
        }
        return classes;
    }
    public List<Classes> getMajor() {
        String sql = "select major from class";
        List<Classes> classes = new ArrayList<Classes>();
        try {
            res = select(sql);
            while (res.next()){
                Classes classes1 = new Classes();
                classes1.setMajor(res.getString("major"));
                classes.add(classes1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DBUtil.close(res,stmt,conn);
        }
        return classes;
    }


    public static void main(String[] args) {
        ClassesDao classesDao = new ClassesDao();
        System.out.println(classesDao.getMajor());
    }
}
